package com.example.photography.adapter.store;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.CategoryBean;
import com.example.photography.util.GridViewForScrollView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 商品分类页
 * 右侧主界面ListView的适配器
 */
public class HomeAdapter extends MyBaseAdapter {
    public HomeAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        } else {
            return 10;
        }
    }

    @Override
    public View myGetView(int position, View convertView) {
        CategoryBean.DataBean dataBean = (CategoryBean.DataBean) list.get(position);
        List<CategoryBean.DataBean.DataListBean> dataList = dataBean.getDataList();
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.store_item_home, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HomeItemAdapter homeItemAdapter = new HomeItemAdapter(dataList,mContext);
        viewHolder.blank.setText(dataBean.getModuleTitle());
        viewHolder.gridView.setAdapter(homeItemAdapter);
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.blank)
        TextView blank;
        @BindView(R.id.gridView)
        GridViewForScrollView gridView;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
